export function successCount(result, count, message) {
  return {
    code: 0,
    result,
    count,
    message
  }
}

export function success(result, message) {
  return {
    code: 0,
    result,
    message
  }
}

export function error(message) {
  return {
    code: -1,
    message
  }
}

export function wrapperResponse(p, msg) {
  return p
    .then(data => success(data, msg))
    .catch(err => error(err.message))
}

export function wrapperCountResponse(dataPromise, countPromise, msg) {
  return Promise.all([dataPromise, countPromise])
    .then(res => {
       const [data, countArr] = res
       return successCount(data, parseInt(countArr[0].count), msg)
    })
    .catch(err => error(err.message))
}
